Skip to content

Support os.Worker on Windows #1003

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Mar 31, 2025
Merged

Conversation

bnoordhuis
Copy link
Contributor

Add thread create/join utility functions and use those to implement os.Worker on the operating system from Redmond.

Add thread create/join utility functions and use those to implement
os.Worker on the operating system from Redmond.
Copy link
Contributor

@saghul saghul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Don't you need to solve the pipe used to signal messages from workers?

@bnoordhuis
Copy link
Contributor Author

Nice! Don't you need to solve the pipe used to signal messages from workers?

Yes. I should've probably opened this as a draft because I wanted to see what the CI does first.

@bnoordhuis
Copy link
Contributor Author

D:\a\quickjs\quickjs\quickjs-c-atomics.h(53,1): fatal error C1083: Cannot open include file: 'stdatomic.h': No such file or directory [D:\a\quickjs\quickjs\build\qjs_exe.vcxproj]

Some of the Windows buildbots have it, some don't. Grr...

@saghul
Copy link
Contributor

saghul commented Mar 30, 2025

I'd be ok making it a requirement. Only the radare folks seemed to want to use an old enough MSVC not to support it.

@bnoordhuis
Copy link
Contributor Author

Assertion failed: list_empty(&rt->gc_obj_list), file D:/a/quickjs/quickjs/quickjs.c, line 2109

It's progress!

Copy link
Contributor

@saghul saghul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with a couple of suggestions.

@@ -10,6 +10,17 @@ set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS ON)
set(CMAKE_C_STANDARD 11)

# MINGW doesn't exist in older cmake versions, newer versions don't know
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, do you know what versions those are?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I didn't mess up my notes: 3.22.1-1ubuntu1 (old), 3.31.6 (new)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to know!

@@ -209,31 +209,6 @@ jobs:
cl.exe /DJS_NAN_BOXING=0 /Zs cxxtest.cc
cl.exe /DJS_NAN_BOXING=1 /Zs cxxtest.cc

windows-msvc-vs2019:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you mention the requirement of atomics in https://quickjs-ng.github.io/quickjs/supported_platforms ?

quickjs-libc.c Outdated
int write_fd;
#endif
} JSWaker;

typedef struct {
int ref_count;
#ifdef USE_WORKER
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know you didn't introduce this, but how about ifdef-ing the whole JSWorkerMessagePipe out?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll try that but I fully expect it to break the wasi build again.

#ifdef USE_WORKER
static void js_waker_close(JSWaker *w)
{
close(w->read_fd);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reset fds to -1?

DWORD ret, timeout = INFINITE;
if (min_delay != -1)
timeout = min_delay;
ret = WaitForMultipleObjects(count, handles, FALSE, timeout);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we not want to explicitly check for WAIT_TIMEOUT for example?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not necessary because WAIT_TIMEOUT is always > count. WaitForMultipleObjects can wait on 64 objects max, WAIT_TIMEOUT is bigger than that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah gotcha!

@bnoordhuis bnoordhuis merged commit 62fb636 into quickjs-ng:master Mar 31, 2025
125 checks passed
@bnoordhuis bnoordhuis deleted the os-worker-win32 branch March 31, 2025 16:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants